package cn.piaoyi.service.imp;

import java.util.*;
import org.apache.commons.logging.*;
import cn.piaoyi.bean.Poster;
import cn.piaoyi.dao.PosterDAO;
import cn.piaoyi.exception.PiaoyiException;
import cn.piaoyi.service.PosterService;


public class PosterServiceImp implements PosterService {

	private static final Log logger = LogFactory.getLog(PosterServiceImp.class);
	
	private PosterDAO posterDAO;

	public PosterDAO getPosterDAO() {
		return posterDAO;
	}

	public void setPosterDAO(PosterDAO posterDAO) {
		this.posterDAO = posterDAO;
	}


	/**
	 * 保存Poster对象
	 * 
	 * @param poster
	 * 			Poster对象
	 * @return Poster
	 * 			Poster对象
	 */
	public Poster createPoster(Poster poster) throws PiaoyiException{
		try {
			poster = this.getPosterDAO().savePoster(poster);
			return poster;
		} catch (Exception e) {
			logger.error(e);
			throw new PiaoyiException(e);
		}
	}

	
	/**
	 * 保存Poster对象
	 * 
	 * @param poster
	 * 			Poster对象
	 * @return Poster
	 * 			Poster对象
	 */
	public Poster updatePoster(Poster poster) throws PiaoyiException{
		try {
			poster = this.getPosterDAO().updatePoster(poster);
			return poster;
		} catch (Exception e) {
			logger.error(e);
			throw new PiaoyiException(e);
		}
	}
	
	/**
	 * 根据主键ID获取Poster对象
	 * 
	 * @param id
	 * 			主键ID
	 * @return Poster
	 * 			Poster对象
	 */
	public Poster findPosterById(long id){
		return this.getPosterDAO().findPosterById(id);
	}
	
	/**
	 * 获取Poster列表
	 * 
	 * @param orderby
	 *            String
	 * @param ascOrDesc
	 *            int
	 * @param firstResult
	 *            int
	 * @param maxResults
	 *            int
	 * @return List
	 * 			Poster对象列表
	 */
	public List findPosters(String orderby, int ascOrDesc, int firstResult, int maxResults){
		List l = this.getPosterDAO().findPosters(orderby, ascOrDesc,firstResult, maxResults);
		if(l == null || l.isEmpty()){
	   		return null;
		}else{
			return l;
		}
	}
	
	/**
	 * 获取Poster列表
	 * 
	 * @param orderby
	 *            String
	 * @param ascOrDesc
	 *            int
	 * @return List
	 * 			Poster对象列表
	 */
	public List findPosters(String orderby, int ascOrDesc){
		List l = this.getPosterDAO().findPosters(orderby, ascOrDesc);
		if(l == null || l.isEmpty()){
	   		return null;
		}else{
			return l;
		}
	}
	
	/**
	 * 删除Poster对象
	 */
	public void removePosterById(long id){
		this.getPosterDAO().removePosterById(id);
	}
}
